﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace WPTrek.Data.Space
{
    public class Galaxy : IGalaxy
    {
        public Galaxy(string name)
        {
            this.name = name;
            sectors = new List<ISector>();
        }

        #region IGalaxy Members

        public string Name
        {
            get
            {
                return name;
            }
        }

        public void AddSector(ISector sector)
        {
            if (sector == null)
                return;

            bool sectorExists = sectors.Where(s => s.ID == sector.ID).Any();
            if (!sectorExists)
            {
                sectors.Add(sector);
            }
        }

        public void AddSectors(IEnumerable<ISector> sectors)
        {
            if (sectors == null)
                return;

            foreach (var s in sectors)
            {
                AddSector(s);
            }
        }

        #endregion

        #region IEnumerable<ISector> Members

        public IEnumerator<ISector> GetEnumerator()
        {
            return sectors.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return sectors.GetEnumerator();
        }

        #endregion


        private List<ISector> sectors;
        private string name;
    }
}
